package com.ruoyi.web.controller.ai_config;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ai_config.domain.AiTaskConfig;
import com.ruoyi.ai_config.service.IAiTaskConfigService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;

/**
 * AI任务配置主Controller
 * 
 * @author lzk
 * @date 2025-06-25
 */
@RestController
@RequestMapping("/ai_config/task")
@Tag(name = "【AI任务配置主】管理")
public class AiTaskConfigController extends BaseController
{
    @Autowired
    private IAiTaskConfigService aiTaskConfigService;

    /**
     * 查询AI任务配置主列表
     */
    @Operation(summary = "查询AI任务配置主列表")
    @PreAuthorize("@ss.hasPermi('ai_config:task:list')")
    @GetMapping("/list")
    public TableDataInfo list(AiTaskConfig aiTaskConfig)
    {
        startPage();
        List<AiTaskConfig> list = aiTaskConfigService.selectAiTaskConfigList(aiTaskConfig);
        return getDataTable(list);
    }

    /**
     * 导出AI任务配置主列表
     */
    @Operation(summary = "导出AI任务配置主列表")
    @PreAuthorize("@ss.hasPermi('ai_config:task:export')")
    @Log(title = "AI任务配置主", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AiTaskConfig aiTaskConfig)
    {
        List<AiTaskConfig> list = aiTaskConfigService.selectAiTaskConfigList(aiTaskConfig);
        ExcelUtil<AiTaskConfig> util = new ExcelUtil<AiTaskConfig>(AiTaskConfig.class);
        util.exportExcel(response, list, "AI任务配置主数据");
    }

    /**
     * 获取AI任务配置主详细信息
     */
    @Operation(summary = "获取AI任务配置主详细信息")
    @PreAuthorize("@ss.hasPermi('ai_config:task:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(aiTaskConfigService.selectAiTaskConfigById(id));
    }

    /**
     * 新增AI任务配置主
     */
    @Operation(summary = "新增AI任务配置主")
    @PreAuthorize("@ss.hasPermi('ai_config:task:add')")
    @Log(title = "AI任务配置主", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AiTaskConfig aiTaskConfig)
    {
        return toAjax(aiTaskConfigService.insertAiTaskConfig(aiTaskConfig));
    }

    /**
     * 修改AI任务配置主
     */
    @Operation(summary = "修改AI任务配置主")
    @PreAuthorize("@ss.hasPermi('ai_config:task:edit')")
    @Log(title = "AI任务配置主", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AiTaskConfig aiTaskConfig)
    {
        return toAjax(aiTaskConfigService.updateAiTaskConfig(aiTaskConfig));
    }

    /**
     * 删除AI任务配置主
     */
    @Operation(summary = "删除AI任务配置主")
    @PreAuthorize("@ss.hasPermi('ai_config:task:remove')")
    @Log(title = "AI任务配置主", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable( name = "ids" ) Long[] ids) 
    {
        return toAjax(aiTaskConfigService.deleteAiTaskConfigByIds(ids));
    }
}
